home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / netscape / applet / DerivedAppletFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  10.5 KB  |  499 lines

  1. package netscape.applet;
  2.  
  3. import java.applet.Applet;
  4. import java.applet.AppletContext;
  5. import java.applet.AppletStub;
  6. import java.awt.BorderLayout;
  7. import java.awt.Component;
  8. import java.awt.Container;
  9. import java.awt.Dimension;
  10. import java.awt.Event;
  11. import java.awt.Frame;
  12. import java.awt.Window;
  13. import java.io.PrintStream;
  14. import java.net.URL;
  15. import java.util.Hashtable;
  16. import java.util.Vector;
  17.  
  18. class DerivedAppletFrame extends EmbeddedAppletFrame implements AppletStub, Runnable, AppletPeer {
  19.    Integer appletID;
  20.    // $FF: renamed from: eq netscape.applet.EventQueue
  21.    EventQueue field_0;
  22.    boolean isAlive;
  23.    boolean isModal;
  24.    Vector topLevelWindows;
  25.    long timestamp;
  26.    boolean inHistory = false;
  27.    URL documentURL;
  28.    URL codebaseURL;
  29.    URL archiveURL;
  30.    Hashtable atts;
  31.    Applet applet;
  32.    int status;
  33.    Thread handler;
  34.    AppletHook hook;
  35.    static final int NULL_EVENT = -1;
  36.    static final int APPLET_DISPOSE = 0;
  37.    static final int APPLET_LOAD = 1;
  38.    static final int APPLET_INIT = 2;
  39.    static final int APPLET_START = 3;
  40.    static final int APPLET_STOP = 4;
  41.    static final int APPLET_DESTROY = 5;
  42.    static final int APPLET_RESIZE = 51234;
  43.    Dimension appletSize = new Dimension(100, 100);
  44.    AppletClassLoader classLoader;
  45.    boolean reloadClasses = false;
  46.    String appletName;
  47.    String currentStatus = "";
  48.    boolean noisy = true;
  49.    String errorReason;
  50.  
  51.    DerivedAppletFrame(URL var1, URL var2, URL var3, Hashtable var4, MozillaAppletContext var5, Integer var6, boolean var7) {
  52.       this.appletID = var6;
  53.       super.pData = var6;
  54.       super.context = var5;
  55.       this.documentURL = var1;
  56.       this.codebaseURL = var2;
  57.       this.archiveURL = var3;
  58.       this.atts = var4;
  59.       ((Container)this).setLayout(new BorderLayout());
  60.       String var8 = this.getParameter("width");
  61.       if (var8 != null) {
  62.          this.appletSize.width = Integer.valueOf(var8);
  63.       }
  64.  
  65.       var8 = this.getParameter("height");
  66.       if (var8 != null) {
  67.          this.appletSize.height = Integer.valueOf(var8);
  68.       }
  69.  
  70.       this.field_0 = new EventQueue();
  71.       this.topLevelWindows = new Vector();
  72.       this.isAlive = true;
  73.       this.isModal = true;
  74.       this.reloadClasses = var7;
  75.    }
  76.  
  77.    void destroy() {
  78.       if (this.status != 0) {
  79.          if (MozillaAppletContext.debug >= 7) {
  80.             System.out.println("# Destroying AppletFrame without disposing: " + this);
  81.          }
  82.  
  83.          ((Frame)this).dispose();
  84.       }
  85.  
  86.       super.destroy();
  87.       this.appletID = null;
  88.       if (this.field_0 != null) {
  89.          this.field_0.destroy();
  90.       }
  91.  
  92.       this.field_0 = null;
  93.       this.topLevelWindows = null;
  94.       this.documentURL = null;
  95.       this.codebaseURL = null;
  96.       this.archiveURL = null;
  97.       this.atts = null;
  98.       this.applet = null;
  99.       this.handler = null;
  100.       this.hook = null;
  101.       this.appletSize = null;
  102.       this.classLoader = null;
  103.       this.appletName = null;
  104.       this.currentStatus = null;
  105.       this.errorReason = null;
  106.    }
  107.  
  108.    protected void finalize() {
  109.       this.destroy();
  110.    }
  111.  
  112.    void dumpState(PrintStream var1, int var2) {
  113.       MozillaAppletContext.indent(var1, var2);
  114.       var1.println("EmbeddedAppletFrame id=" + super.pData + " applet=" + this.applet);
  115.    }
  116.  
  117.    String statusToString(int var1) {
  118.       switch (var1) {
  119.          case 0:
  120.             return "dispose";
  121.          case 1:
  122.             return "load";
  123.          case 2:
  124.             return "init";
  125.          case 3:
  126.             return "start";
  127.          case 4:
  128.             return "stop";
  129.          case 5:
  130.             return "destroy";
  131.          default:
  132.             return Integer.toString(var1, 10);
  133.       }
  134.    }
  135.  
  136.    public Dimension minimumSize() {
  137.       return new Dimension(this.appletSize.width, this.appletSize.height);
  138.    }
  139.  
  140.    public Dimension preferredSize() {
  141.       return this.minimumSize();
  142.    }
  143.  
  144.    public void requestShutdown() {
  145.       this.field_0.sendEvent(new AppletEvent(4));
  146.       this.field_0.sendEvent(new AppletEvent(5));
  147.       this.field_0.sendEvent(new AppletEvent(0));
  148.    }
  149.  
  150.    public void start() {
  151.       SecurityManager.enablePrivilege("UniversalThreadAccess");
  152.       SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
  153.       this.handler = new Thread(new AppletThreadGroup("applet-" + this.atts.get("code"), this), this);
  154.       SecurityManager.revertPrivilege();
  155.       this.handler.start();
  156.    }
  157.  
  158.    public void run() {
  159.       String var1 = null;
  160.       if (this.getParameter("mayscript") != null) {
  161.          var1 = this.documentURL.toString();
  162.       }
  163.  
  164.       this.classLoader = AppletClassLoader.getClassLoader(super.context, this.codebaseURL, this.archiveURL, var1, this.reloadClasses);
  165.  
  166.       while(this.isAlive && this.isModal) {
  167.          NEvent var2;
  168.          try {
  169.             var2 = this.field_0.getNextEvent();
  170.          } catch (Exception var21) {
  171.             this.showAppletException(var21, "interrupted, bailing out...");
  172.             return;
  173.          }
  174.  
  175.          try {
  176.             switch (var2.eventId) {
  177.                case 0:
  178.                   if (this.status == 1) {
  179.                      this.status = 0;
  180.                      ((Container)this).remove(this.applet);
  181.                      this.applet = null;
  182.                      this.rightState("disposed");
  183.                      ((Frame)this).dispose();
  184.                      Vector var35 = this.topLevelWindows;
  185.                      synchronized(var35){}
  186.  
  187.                      try {
  188.                         for(int var6 = this.topLevelWindows.size(); var6 > 0; --var6) {
  189.                            ((Window)this.topLevelWindows.elementAt(var6 - 1)).dispose();
  190.                         }
  191.                      } catch (Throwable var30) {
  192.                         throw var30;
  193.                      }
  194.  
  195.                      this.isAlive = false;
  196.                      return;
  197.                   }
  198.  
  199.                   this.wrongState("can't dispose", "applet not destroyed");
  200.                   break;
  201.                case 1:
  202.                   if (this.status != 0) {
  203.                      this.wrongState("can't load", "not disposed");
  204.                   } else {
  205.                      String var3 = this.getParameter("code");
  206.                      if (var3.endsWith(".class")) {
  207.                         var3 = var3.substring(0, var3.length() - 6).replace('/', '.');
  208.                      }
  209.  
  210.                      if (var3.endsWith(".java")) {
  211.                         var3 = var3.substring(0, var3.length() - 5).replace('/', '.');
  212.                      }
  213.  
  214.                      try {
  215.                         Class var4 = Class.forName("java.applet.Applet");
  216.                         Class var5 = this.classLoader.loadClass(var3);
  217.                         if (!var4.isAssignableFrom(var5)) {
  218.                            throw new ClassCastException(var3 + " is not an applet");
  219.                         }
  220.  
  221.                         this.applet = (Applet)var5.newInstance();
  222.                      } catch (VerifyError var22) {
  223.                         this.showAppletException(var22, "class " + ((Throwable)var22).getMessage() + " got a security violation: method verification error");
  224.                         continue;
  225.                      } catch (SecurityException var23) {
  226.                         this.showAppletException(var23, "class " + var3 + " got a security violation: " + ((Throwable)var23).getMessage());
  227.                         continue;
  228.                      } catch (ClassNotFoundException var24) {
  229.                         this.showAppletException(var24, "class " + var3 + " not found");
  230.                         continue;
  231.                      } catch (InstantiationException var25) {
  232.                         this.showAppletException(var25, "class " + var3 + " can't be instantiated");
  233.                         continue;
  234.                      } catch (IllegalAccessException var26) {
  235.                         this.showAppletException(var26, "class " + var3 + " is not public or has no public constructor");
  236.                         continue;
  237.                      } catch (Exception var27) {
  238.                         this.showAppletException(var27, "exception: " + ((Throwable)var27).toString());
  239.                         continue;
  240.                      } catch (ThreadDeath var28) {
  241.                         this.showAppletStatus("killed");
  242.                         return;
  243.                      } catch (Error var29) {
  244.                         this.showAppletException(var29, "error: " + ((Throwable)var29).toString());
  245.                         continue;
  246.                      }
  247.  
  248.                      this.applet.setStub(this);
  249.                      this.applet.hide();
  250.                      ((Container)this).add("Center", this.applet);
  251.                      this.status = 1;
  252.                      this.rightState("loaded");
  253.                      ((Container)this).validate();
  254.                   }
  255.                   break;
  256.                case 2:
  257.                   if (this.status != 1) {
  258.                      this.wrongState("can't init", "applet not loaded");
  259.                   } else {
  260.                      ((Window)this).pack();
  261.                      ((Window)this).show();
  262.                      this.applet.resize(this.appletSize);
  263.                      AppletDebugger.aboutToInit(this.applet);
  264.                      this.applet.init();
  265.                      ((Container)this).validate();
  266.                      this.status = 2;
  267.                      this.rightState("initialized");
  268.                   }
  269.                   break;
  270.                case 3:
  271.                   if (this.status != 2) {
  272.                      this.wrongState("can't start", "applet not initialized");
  273.                   } else {
  274.                      this.status = 3;
  275.                      this.timestamp = System.currentTimeMillis();
  276.                      this.applet.resize(this.appletSize.width, this.appletSize.height);
  277.                      this.applet.start();
  278.                      this.applet.show();
  279.                      ((Container)this).validate();
  280.                      super.context.mochaOnLoad(0);
  281.                      this.rightState("running");
  282.                   }
  283.                   break;
  284.                case 4:
  285.                   if (this.status != 3) {
  286.                      this.wrongState("can't stop", "applet not started");
  287.                   } else {
  288.                      this.status = 2;
  289.                      this.timestamp = System.currentTimeMillis();
  290.                      this.applet.hide();
  291.                      SecurityManager.enablePrivilege("UniversalThreadAccess");
  292.                      this.applet.stop();
  293.                      SecurityManager.revertPrivilege();
  294.                      this.rightState("stopped");
  295.                   }
  296.                   break;
  297.                case 5:
  298.                   if (this.status != 2) {
  299.                      this.wrongState("can't destroy", "applet not stopped");
  300.                   } else {
  301.                      this.status = 1;
  302.                      SecurityManager.enablePrivilege("UniversalThreadAccess");
  303.                      this.applet.destroy();
  304.                      SecurityManager.revertPrivilege();
  305.                      ((Component)this).hide();
  306.                      this.rightState("destroyed");
  307.                   }
  308.                   break;
  309.                case 20:
  310.                   var2.processEvent();
  311.                case 51234:
  312.             }
  313.          } catch (SecurityException var31) {
  314.             this.showAppletException(var31, "security violation: " + ((Throwable)var31).getMessage());
  315.          } catch (Exception var32) {
  316.             this.showAppletException(var32, "exception: " + ((Throwable)var32).toString());
  317.          } catch (ThreadDeath var33) {
  318.             this.showAppletStatus("killed");
  319.             return;
  320.          } catch (Error var34) {
  321.             this.showAppletException(var34, "error: " + ((Throwable)var34).toString());
  322.          }
  323.       }
  324.  
  325.    }
  326.  
  327.    public boolean isActive() {
  328.       return this.status == 3;
  329.    }
  330.  
  331.    public String getParameter(String var1) {
  332.       return this.atts != null ? (String)this.atts.get(var1.toLowerCase()) : null;
  333.    }
  334.  
  335.    public URL getDocumentBase() {
  336.       return this.documentURL;
  337.    }
  338.  
  339.    public URL getCodeBase() {
  340.       return this.codebaseURL;
  341.    }
  342.  
  343.    public AppletContext getAppletContext() {
  344.       return super.context;
  345.    }
  346.  
  347.    public void appletResize(int var1, int var2) {
  348.       this.appletSize.width = var1;
  349.       this.appletSize.height = var2;
  350.       ((Component)this).postEvent(new Event(this, 51234, this.preferredSize()));
  351.    }
  352.  
  353.    public void setAppletSize(int var1, int var2, int var3, int var4) {
  354.    }
  355.  
  356.    public String getAppletName() {
  357.       if (this.appletName == null) {
  358.          try {
  359.             if (this.applet != null) {
  360.                this.appletName = this.applet.getParameter("name");
  361.                if (this.appletName == null) {
  362.                   this.appletName = this.applet.getClass().getName().toString();
  363.                }
  364.             } else {
  365.                this.appletName = this.getParameter("code");
  366.                int var1 = this.appletName.lastIndexOf(".class");
  367.                if (var1 != -1) {
  368.                   this.appletName = this.appletName.substring(0, var1);
  369.                }
  370.             }
  371.          } catch (Exception var2) {
  372.             this.appletName = "?";
  373.          }
  374.       }
  375.  
  376.       return this.appletName;
  377.    }
  378.  
  379.    protected void showAppletStatus(String var1) {
  380.       String var2 = this.getAppletName();
  381.       this.currentStatus = "Applet " + var2 + " " + var1;
  382.       this.getAppletContext().showStatus(this.currentStatus);
  383.       if (MozillaAppletContext.debug >= 1) {
  384.          System.err.println("# " + this.currentStatus);
  385.       }
  386.  
  387.    }
  388.  
  389.    protected void showAppletLog(String var1) {
  390.       if (this.noisy) {
  391.          String var2;
  392.          if (this.applet == null) {
  393.             var2 = "# Applet log: " + var1;
  394.          } else {
  395.             String var3 = this.getAppletName();
  396.             var2 = "# Applet " + var3 + " " + " log: " + var1;
  397.          }
  398.  
  399.          System.err.println(var2);
  400.       }
  401.  
  402.    }
  403.  
  404.    protected void rightState(String var1) {
  405.       this.errorReason = null;
  406.       this.showAppletStatus(var1);
  407.    }
  408.  
  409.    protected void wrongState(String var1, String var2) {
  410.       this.showAppletStatus(var1 + ": " + (this.errorReason != null ? this.errorReason : var2));
  411.       if (MozillaAppletContext.debug >= 7) {
  412.          System.err.println("#   status=" + this.status);
  413.       }
  414.  
  415.    }
  416.  
  417.    protected void showAppletException(Throwable var1, String var2) {
  418.       if (this.noisy) {
  419.          super.context.mochaOnLoad(-1);
  420.          if (var2 == null) {
  421.             var2 = var1.toString();
  422.          }
  423.  
  424.          this.errorReason = var2;
  425.          System.err.println("# Applet exception: " + var2);
  426.          var1.printStackTrace();
  427.          this.showAppletStatus(var2);
  428.       }
  429.  
  430.    }
  431.  
  432.    public boolean mouseEnter(Event var1, int var2, int var3) {
  433.       this.getAppletContext().showStatus(this.currentStatus);
  434.       return true;
  435.    }
  436.  
  437.    public boolean mouseExit(Event var1, int var2, int var3) {
  438.       this.getAppletContext().showStatus("");
  439.       return true;
  440.    }
  441.  
  442.    EventQueue getEventQueue() {
  443.       return this.field_0;
  444.    }
  445.  
  446.    public Thread getAppletThread() {
  447.       return this.handler;
  448.    }
  449.  
  450.    public void sendEvent(NEvent var1) {
  451.       this.field_0.sendEvent(var1);
  452.    }
  453.  
  454.    public void enterModal() {
  455.       this.run();
  456.       this.isModal = true;
  457.    }
  458.  
  459.    public void exitModal() {
  460.       this.isModal = false;
  461.    }
  462.  
  463.    public void addTopLevelWindow(Window var1) {
  464.       Vector var2 = this.topLevelWindows;
  465.       synchronized(var2){}
  466.  
  467.       try {
  468.          if (var1 != this) {
  469.             this.topLevelWindows.addElement(var1);
  470.          }
  471.       } catch (Throwable var4) {
  472.          throw var4;
  473.       }
  474.  
  475.    }
  476.  
  477.    public void removeTopLevelWindow(Window var1) {
  478.       Vector var2 = this.topLevelWindows;
  479.       synchronized(var2){}
  480.  
  481.       try {
  482.          if (var1 != this) {
  483.             this.topLevelWindows.removeElement(var1);
  484.          }
  485.       } catch (Throwable var4) {
  486.          throw var4;
  487.       }
  488.  
  489.    }
  490.  
  491.    public void removeEvents(Object var1) {
  492.       this.field_0.removeEvents(var1);
  493.    }
  494.  
  495.    public void coalesceEvent(NEvent var1) {
  496.       this.field_0.coalesceEvent(var1);
  497.    }
  498. }
  499.